<template>
  <div class="take-order">
    <OrderListItem v-for="item in maintainList" :key="item.id" :maintaindata="item"></OrderListItem>
  </div>
</template>

<script>
import OrderListItem from '@/components/maintainer/OrderListItem.vue'
import { getMaintainListService } from '@/api/maintainer'
// import { formatDate } from '@/utils/formatDate'
export default {
  data () {
    return {
      maintainList: []
    }
  },
  created () {
    this.getMaintainList()
  },
  methods: {
    async getMaintainList () {
      const res = await getMaintainListService()
      if (res.status === 1) return
      res.data.forEach((item, index, arr) => {
        const data = new Date(item.create_time).toJSON()
        item.create_time = new Date(+new Date(data) + 8 * 3600 * 1000)
          .toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
        let data1 = ''
        let data2 = ''
        if (item.take_time) {
          data1 = new Date(item.take_time).toJSON()
          item.take_time = new Date(+new Date(data1) + 8 * 3600 * 1000)
            .toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
        }
        if (item.done_time) {
          data2 = new Date(item.done_time).toJSON()
          item.done_time = new Date(+new Date(data2) + 8 * 3600 * 1000)
            .toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
        }

        switch (item.order_status) {
          case '1':
            item.order_status = '待接单'
            return
          case '2':
            item.order_status = '预约成功'
            return
          case '3':
            item.order_status = '进行中'
            return
          case '4':
            item.order_status = '已完成'
            return
          case '5':
            item.order_status = '待评价'
            return
          default:
            item.order_status = '已评价'
        }
        // item.create_time = formatDate(item.create_time)
      })
      this.maintainList = res.data
    }
  },
  computed: {

  },
  components: {
    OrderListItem
  }
}
</script>

<style lang="less" scoped></style>
